var _n52;
var cc__extends = __extends;
var cc__decorate = __decorate;
var cc__importDefault = __importDefault;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var cc_uiService = require("uiService");
var zqcc_uiService = cc__importDefault(cc_uiService);
var cc_OverallSystem = require("zqcc_OverallSystem");
var cc_zqcc_pageBase = require("zqcc_pageBase");
var zqcc_pageBase = cc__importDefault(cc_zqcc_pageBase);
var cc_cc__decorator = cc._decorator;
var cc_ccp_ccclass = cc_cc__decorator.ccclass;
var cc_ccp_property = cc_cc__decorator.property;
var def_dialog = function (t) {
  function _ctor() {
    // 创建对话框对象, 如果 t 是函数则调用它
    let dialog = null !== t && t.apply(this, arguments) || this;

    // 初始化对话框的属性
    dialog.pageName = "对话框";
    dialog.title = null;
    dialog.message = null;
    dialog.confirmBtn = null;
    dialog.zqcc_videoAdCB = null;
    dialog.isVideoAd = false;
    dialog.videoAdCnt = 0;
    dialog.videoAdLookCnt = 0;
    dialog.lookVideoSource = "";

    // 返回对话框对象
    return dialog;

  }
  cc__extends(_ctor, t);
  _ctor.prototype.onLoad = function () { };
  _ctor.prototype.start = function () {
    this.zqcc_init();
  };
  _ctor.prototype.zqcc_setDate = function (t, e, o, n, i, r, a) {
    // 为变量赋予默认值
    e = (e !== undefined) ? e : "温馨提示";
    n = (n !== undefined) ? n : false;
    i = (i !== undefined) ? i : 0;

    // 将值赋给对象属性
    this.title.string = e;
    this.message.string = t;
    this.colseDoFun = o; // 修正拼写错误
    this.isVideoAd = n;
    this.videoAdCnt = i;
    this.zqcc_videoAdCB = r;
    this.lookVideoSource = a;
  };
  _ctor.prototype.zqcc_init = function () {
    // 查找按钮布局
    var btnLayout = cc.find("showLayout/btnLayout", this.showNode);
    var btnX = cc.find("showLayout/panel/btnX", this.showNode);

    // 设置按钮的激活状态
    btnX.active = !this.isVideoAd;
    btnLayout.active = this.isVideoAd;

    if (this.isVideoAd) {
      var confirmLabel = this.confirmBtn.getChildByName("cnt").getComponent(cc.Label);

      // 更新确认按钮的可见性和视频计数
      confirmLabel.node.active = this.videoAdCnt > 1;

      if (this.videoAdCnt > 1) {
        this.zqcc_updateVideoCnt();
      }
    }

    // 打开当前界面
    this.zqcc_open();

  };
  _ctor.prototype.zqcc_open = function () {
    zqcc_uiService.default.openPageBasicAni(this.showNode, true).then(function () { });
  };
  _ctor.prototype.close = function () {
    var t = this;
    this.zqcc_closeAni().then(function () {
      cc_OverallSystem.sers().uiSrv.deletePageRecord(t.id);
    });
  };
  _ctor.prototype.OnBtnClose = function () {
    // 播放按钮声音
    cc_OverallSystem.mgrs().soundMgr.playBtnSound();

    // 执行关闭动画并处理回调
    this.zqcc_closeAni().then(() => {
      if (this.closeDoFun) {
        this.closeDoFun();  // 调用关闭后的回调函数
      }
      cc_OverallSystem.sers().uiSrv.deletePageRecord(this.id); // 删除页面记录
    });

  };
  _ctor.prototype.OnBtnConfirm = function () {
    // 播放按钮声音
    cc_OverallSystem.mgrs().soundMgr.playBtnSound();

    // 判断是否为视频广告并加载视频广告
    if (this.isVideoAd) {
      cc_OverallSystem.sers().platformSrv.platformApi.loadAndShowVideoAd(
        () => {
          this.videoAdLookCnt++;
          this.zqcc_updateVideoCnt();

          // 如果观看次数达到预期，执行关闭动画
          if (this.videoAdLookCnt >= this.videoAdCnt) {
            this.zqcc_closeAni().then(() => {
              cc_OverallSystem.sers().uiSrv.deletePageRecord(this.id);
              if (this.zqcc_videoAdCB) {
                this.zqcc_videoAdCB();
              }
            });
          }
        },
        (error) => {
          console.error(error); // 直接输出错误信息
        },
        null,
        this.lookVideoSource
      );
    }

  };
  _ctor.prototype.zqcc_closeAni = function (t) {
    undefined === t && (t = true);
    return zqcc_uiService.default.closePageBasicAni(this.showNode, t);
  };
  _ctor.prototype.zqcc_updateVideoCnt = function () {
    this.videoAdCnt > 1 && (this.confirmBtn.getChildByName("cnt").getComponent(cc.Label).string = "( " + this.videoAdLookCnt + " / " + this.videoAdCnt + " )");
  };
  _ctor.prototype.update = function () { };
  cc__decorate([cc_ccp_property({
    type: cc.Label,
    displayName: "标题"
  })], _ctor.prototype, "title", undefined);
  cc__decorate([cc_ccp_property({
    type: cc.Label,
    displayName: "内容"
  })], _ctor.prototype, "message", undefined);
  cc__decorate([cc_ccp_property({
    type: cc.Node,
    displayName: "确认按钮"
  })], _ctor.prototype, "confirmBtn", undefined);
  return cc__decorate([cc_ccp_ccclass], _ctor);
}(zqcc_pageBase.default);
exports.default = def_dialog;